#include <iostream>
using namespace std;

class Student{
    private:
        string name;
        int age;
    public:
        Student():name(""),age(0){
            cout << "无参构造函数" << endl;
        }
        Student(string n, int a):name(n), age(a){
            cout << "有参构造函数" << endl;
        }
        // 拷贝构造函数
        // 拷贝构造函数也支持初始化列表的写法
        //Student(const Student &other):name(other.name), age(other.age){
        Student(const Student &other){
            cout << "拷贝构造函数" << endl;
            this->name = other.name;
            this->age = other.age;
        }
        ~Student(){
            cout << "析构函数" << endl;
        }
        void show(){
            cout << name << " " << age << endl;
        }
};

int main(int argc, const char *argv[]){
    Student s1("小明", 18); // 有参构造
    Student s2; // 无参构造
    // 从编译器的角度: s3.Student(s1);
    Student s3(s1); // 拷贝构造
    // 从编译器的角度: s4.Student(s3);
    Student s4 = s3; // 拷贝构造

    s1.show();
    s2.show();
    s3.show();
    s4.show();

    return 0;
}